package com.zhang.flink;

/**
 * @author Alger
 * @date 2021/11/12  16:43
 */

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 流处理
 */
public class StreamWordCount {

    public static void main(String[] args) throws Exception {
        //流处理环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> streamSource = env.readTextFile("E:\\workspace\\jqyh\\flink_test\\src\\main\\resources\\hello.txt");
        SingleOutputStreamOperator<Tuple2<String, Integer>> resultStream = streamSource.flatMap(new WordCount.MyFlatMapper()).keyBy(0).sum(1);

        resultStream.print();

        env.execute();

    }
}
